//
//  CreditCardViewController.m
//  FuncFanc
//
//  Created by careate-hubing on 2021/5/28.
//  Copyright © 2021 huhu. All rights reserved.
//

#import "CreditCardViewController.h"
#import "CreditCardCell.h"


@interface CreditCardViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation CreditCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createSubviews];
}

-(void)createSubviews
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[CreditCardCell class] forCellReuseIdentifier:NSStringFromClass([CreditCardCell class])];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CreditCardCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CreditCardCell class])];
    if (!cell) {
        cell = [[CreditCardCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([CreditCardCell class])];
    }
    
    [cell configCardCellWith:@""];
    
    return cell;
}

-(void)loadDataFormDB
{
    
//    NSArray *array = @[@[@"card1",@"card2"],@[@"card1",@"card2"],@[@"card1"]];
    
    NSMutableArray *tempArr = [NSMutableArray array];
    
    LKDBHelper *helper = [LKDBHelper getUsingLKDBHelper];
    NSArray *userResult = [helper search:[UserModel class] where:nil orderBy:nil offset:0 count:INT_MAX];
   
    for (UserModel *user in userResult) {
        NSMutableArray *cardArr = [NSMutableArray array];
        NSArray *cardResult = [helper search:[CreditCardModel class] where:@{@"cardUser":user} orderBy:nil offset:0 count:INT_MAX];
        for (CreditCardModel *card in cardResult) {
            [cardArr addObject:card];
        }
        [tempArr addObject:cardArr];
    }
    
    
}





@end
